import React, { useEffect, useState } from "react"
import type { ReactNode } from "react"
import "./index.less"
interface Iprops {
	children?: ReactNode
	link: string
}
const PdfView: React.FC<Iprops> = (props) => {
	const { link } = props
	const [url, setUrl] = useState<string>("")
	useEffect(() => {
		getPdfFile()
	}, [link])
	const getPdfFile = () => {
		setUrl("pdf/web/viewer.html?file=" + link)
		/* fetch(link)
			.then((response) => {
				console.log(response)
				return response.blob()
			})
			.then((data) => {
				console.log(data)
				const objectURL = URL.createObjectURL(data)
				// iframe
				setUrl("pdfjs/web/viewer.html?file=" + objectURL)
			})
			.catch((error) => {
				console.error("Error:", error)
			}) */
	}
	return (
		<div className="pdfcon">
			<iframe className="pdf" src={url} frameBorder="0"></iframe>
		</div>
	)
}

export default PdfView
